﻿
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;

public class Main : MonoBehaviour
{
    public Transform RootTf;
    public Button ChangeMinisterEquipMent;
    public Button ChangeCaptainEquipMent;
    private PersonBase captain2;
    private PersonBase minister2;

    //武器列表
    private List<string> weaponList = new List<string>()
    {
        "Weapon_Short_Front_A_01",
        "Weapon_Short_Front_A_02",
        "Weapon_Short_Front_B_01",
        "Weapon_Short_Front_B_02",
        "Weapon_Short_Front_B_03",
    };

    //帽子列表
    private List<string> hatList = new List<string>()
    {
        "BG_hat01",
        "BG_hat02",
        "BG_hat03",
        "BG_hat04",
        "BG_hat05",
    };
    public void Awake()
    {
        ChangeCaptainEquipMent.onClick.AddListener(OnclickChangeCaptainEquipMent);
        ChangeMinisterEquipMent.onClick.AddListener(OnclickChangeMinisterEquipMent);
        //工厂方法 + 模板模式 生成名臣小人
        IPersonFactory ministerFactory = new MinisterFactory();
        minister2 = ministerFactory.CreatePerson(RootTf);
        minister2.ShowPreView();
       
        
        //抽象工厂 + 模板模式 生成武将和武器以及名臣帽子
        IBaseFactory personFactory = new PersonFactory();
        IBaseFactory equipmentFactory = new EquipmentFactory();
        //武将
        captain2 = personFactory.GetPerson<Captain>(RootTf,"Prefabs/Captain");
        EquipmentBase weapon = equipmentFactory.GetEquipment<WeaponEquipment>();
        weapon.SetEquipName("Weapon_Short_Front", "Weapon_Short_Front_A_01");
        captain2.AddEquipment(weapon);
        captain2.ShowPreView();
        //名臣 帽子
        EquipmentBase hats = equipmentFactory.GetEquipment<HatsEquipment>();
        hats.SetEquipName("slot_hat", "BG_hat11");
        minister2.AddEquipment(hats);
    }

    private void OnclickChangeMinisterEquipMent()
    {
        minister2.Equipment.SetEquipName("slot_hat",hatList[Random.Range(0,hatList.Count)]);
        minister2.RefreshEquipment();
    }

    private void OnclickChangeCaptainEquipMent()
    {
        captain2.Equipment.SetEquipName("Weapon_Short_Front",weaponList[Random.Range(0,weaponList.Count)]);
        captain2.RefreshEquipment();
    }

    private void OnDestroy()
    {
        ChangeCaptainEquipMent.onClick.RemoveAllListeners();
        ChangeMinisterEquipMent.onClick.RemoveAllListeners();
    }
}
